from urllib import request
import codecs
def usage():
    """print the command line usage"""
    print("Usage: web2file.py webadress outputfilename")
def download(htmladress, outputfilename):
    """open htmladdress, then duplicate the contents to outputfilename(on local machine), uses codecs.open in case unicode character is in htmladdress"""
    print("Opening: " + htmladdress)
    webfile = request.urlopen(htmladdress)
    contents = webfile.read()
    print("Writing contents to: " + outputfilename)
    with codecs.open(outputfilename, mode="wb")) as f:
        f.write(contents)
if __name__ == "__main__":
    import sys
    if len(sys.argv) > 1:
        download(sys.argv[1], sys.argv[2])
    else:
        usage()